import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import electron from 'vite-plugin-electron';
import { resolve } from 'path';
import svgLoader from 'vite-svg-loader';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
import { rmSync } from 'fs';
rmSync('dist', { recursive: true, force: true });
// rmSync('dist_electron', { recursive: true, force: true });
// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  resolve: {
    alias: {
      '@': resolve('src')
    }
  },

  plugins: [
    vue(),
    svgLoader(),
    AutoImport({
      imports: [
        'vue',
        {
          'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar']
        }
      ]
    }),
    Components({
      resolvers: [NaiveUiResolver()]
    }),
    // https://www.electron.build/configuration/configuration
    electron({
      entry: 'electron/main.ts',
      onstart: options => {
        // Start Electron App
        options.startup(['.', '--no-sandbox']);
      }
      // vite: {
      //   build: {
      //     rollupOptions: {
      //       // Here are some C/C++ plugins that can't be built properly.
      //       external: [
      //         'serialport',
      //         'sqlite3',
      //       ],
      //     },
      //   },
      // }
    })
  ],
  build: {
    // assetsDir: 'assets',
    chunkSizeWarningLimit: 10000,
    minify: 'esbuild',
    sourcemap: false
  }
});
